package com.wolfsea.pagerecyclerviewdemo
import android.os.Bundle
import android.util.Log
import com.wolfsea.pagerecyclerviewdemo.databinding.ActivityMainBinding

class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::inflate),
    PagingScrollHelper2.OnPageChangeListener {

    override fun init(savedInstanceState: Bundle?) {

        val contentDataList = mutableListOf<ContentData>()

        val dataArray = arrayOf(
            "统信软件",
            "鲲鹏",
            "创新中心",
            "工具",
            "应用范围",
            "递归",
            "嵌套",
            "进程",
            "性能",
            "最大限度",
            "循环",
            "汇编代码",
            "重要",
            "事实上",
            "编写",
            "六个月",
            "优惠券",
            "安装",
            "鲜明对比",
            "应用商店",
            "调查",
            "芯片",
            "可能",
            "消息",
            "相关人士",
            "关系部门",
            "投资人",
            "暴雪",
            "解决方案",
            "发布",
            "是编程中",
            "重要",
            "概念",
            "高级语言",
            "得到",
            "广泛",
            "应用",
            "硬件层",
            "实现",
            "重要性",
            "不言而喻",
            "但是",
            "现代编程",
            "许多",
            "语言",
            "完全可以",
            "使用循环",
            "我们",
            "利用",
            "函数",
            "映射",
            "解析式",
            "实现",
            "相同",
            "功能",
            "但是",
            "情况下",
            "关键字",
            "关键字",
            "跳过",
            "元素",
            "加快",
            "目前",
            "可用模型",
            "还不够好",
            "不足以",
            "生命科学",
            "领域",
            "重大影响",
            "科学家",
            "都说",
            "只能",
            "只能",
            "情况下",
            "发挥些许",
            "作用",
            "基因组",
            "前景的",
            "应用方向",
            "尚属",
            "起步阶段",
            "看好",
        )

        for (item in dataArray) {
            contentDataList.add(ContentData(R.drawable.ic_launcher00, item))
        }

        val scrollHelper = PagingScrollHelper2()
        scrollHelper.setUpRecyclerView(mBinding.pageRv)
        scrollHelper.setOnPageChangeListener(this)
        scrollHelper.updateLayoutManager()
        scrollHelper.scrollToPosition(0)
        val horizontalPageLayoutManager =
            HorizontalPageLayoutManager2(
                this@MainActivity,
                6,
                4
            )
        //默认滑动到第一页
        mBinding.pageRv.isHorizontalScrollBarEnabled = true
        mBinding.pageRv.layoutManager = horizontalPageLayoutManager
        mBinding.pageRv.adapter = PageRvAdapter(contentDataList)

        mBinding.circlePageIndicator.setItemCount(horizontalPageLayoutManager.getPageSize())
    }

    override fun onPageChange(index: Int) {
        Log.d(TAG, "index:${index}")
        mBinding.circlePageIndicator.updateIndex(index)
    }

    companion object {
        const val TAG = "MainActivity"
    }

}